//
//  Int.swift
//  CMKit
//
//  Created by traselfel on 2016/12/15.
//  Copyright © 2016年 coselfermedia. All rights reserselfed.
//

import Foundation
import UIKit

public extension Int {
    
    /// 返回繁体表示
    public var tradition: String {
        let keys = ["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]
        switch self {
        case 1...9:
            return keys[self - 1]
        case 10...99:
            return (self / 10).tradition + "拾" + (self % 10).tradition
        case 100...999:
            return (self / 100).tradition + "佰" + (self % 100).tradition
        case 1_000...9_999:
            return (self / 1_000).tradition + "仟" + (self % 1_000).tradition
        case 10_000...99_999_999:
            return (self / 10_000).tradition + "万" + (self % 10_000).tradition
        case let x where x > 99_999_999:
            return  (self / 100_000_000).tradition + "亿" + (self % 100_000_000).tradition
        case let x where x < 0:
            return "负" + (-self).tradition
        default:
            return ""
        }
    }
}


private let kIscale = CGFloat(UIScreen.main.scale)
private let kIbounds = UIScreen.main.bounds
private let (kIscreenWidth, kIscreenHeight) = kIbounds.width < kIbounds.height ? (CGFloat(kIbounds.width), CGFloat(kIbounds.height)) : (CGFloat(kIbounds.height), CGFloat(kIbounds.width))

public extension Int {
    
    /// 当前设备占用像素
     public var pixel: CGFloat {
        let mod = CGFloat(self % 3) / kIscale
        return CGFloat(self / 3) + mod
    }
    
    /// 当前设备水平方向比例缩放后像素
    public var pixelRatioHor: CGFloat {
        let ratio = Int(CGFloat(self) * kIscreenWidth * 3 / 1242)
        let mod = CGFloat(ratio % 3) / kIscale
        return CGFloat(ratio / 3) + mod
    }
    
    /// 当前设备垂直方向比例缩放后像素
    public var pixelRatioVert: CGFloat {
        let ratio = Int(CGFloat(self) * kIscreenHeight * 3 / 2208)
        let mod = CGFloat(ratio % 3) / kIscale
        return CGFloat(ratio / 3) + mod
    }
}
